import { fetchSlot,fetchSlotDetailBySlotId, saveQA, getQaId, getKnowledgeDetail,getAlikeQuestionList,getStandardQuestion,getAnswer,fakeAnswerRelevanceData,processGuide,editProcessGuide} from '@/services/knowledgegraph';
import { fetchApiListById,slotList,fetchApiDetailById} from '@/services/basiccapacity';
import { getList,knowledgeClassification,answerCategory } from '@/services/knowledgemanagement';
import { routerRedux } from 'dva/router';

export default {
  namespace: 'intentionsList',
  state: {
    total: null,
    data: [],
    loading: false
  },

  effects: {
    *fetchSlot({payload,callback}, { call, put }) {
      const response = yield call(slotList,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *fetchApi({payload,callback}, { call, put }) {
      const response = yield call(fetchApiListById,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *fetchApiDetailById({payload,callback}, { call, put }) {
      const response = yield call(fetchApiDetailById,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *getDictItemFromSlotId({payload,callback}, { call, put }) {
      const response = yield call(fetchSlotDetailBySlotId,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *saveQA({payload,callback}, { call, put }) {
      const response = yield call(saveQA,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *getQaId({payload,callback}, { call, put }) {
      const response = yield call(getQaId,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *getKnowledgeDetail({payload,callback}, { call, put }) {
      const response = yield call(getKnowledgeDetail,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *getAlikeQuestionList({payload,callback}, { call, put }) {
      const response = yield call(getAlikeQuestionList,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *getStandardQuestion({payload,callback}, { call, put }) {
      const response = yield call(getStandardQuestion,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *getAnswer({payload,callback}, { call, put }) {
      const response = yield call(getAnswer,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *linkBoxJson({payload,callback}, { call, put }) {
      const response = yield call(fakeAnswerRelevanceData,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *processGuide({payload,callback}, { call, put }) {
      const response = yield call(processGuide,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *editProcessGuide({payload,callback}, { call, put }) {
      const response = yield call(editProcessGuide,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *getQuoteAnswer({payload,callback}, { call, put }) {
      const response = yield call(getList,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *categoryListJson({payload,callback}, { call, put }) {
      const response = yield call(knowledgeClassification,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *getAnswerCategory({payload,callback}, { call, put }) {
      const response = yield call(answerCategory,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    }
  }
};
